home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- *
- * Copyright Apple Computer, Inc. 1986,1992, 1995
- * All Rights Reserved
- *
- * Description: This program reads code segment 1 from a specified
- * Resource file, calculates the crc value, then
- * patches the CRC value into the segment. Run this
- * tool after assembling and linking the declaration
- * ROM file. Next, run the Data tool to transfer the
- * CODE 1 segment into a data file. The data file can
- * then be down-loaded into a ROM programmer.
- *
- * Calling syntax: crcPatch filename
- *
- * Written: July 30, 1986.
- *
- * Modified: 9/16/92.
- * • Changed this header to be more readable.
- * • Fixed bug that caused possible bus error in
- * 32 bit mode when skipping over first 4 bytes of
- * the resource header
- *
- **********************************************************************/
-
-
- #include <stdio.h>
- #include <types.h>
- #include <osutils.h>
- #include <files.h>
- #include <resources.h>
- #include <memory.h>
- #include <errno.h>
-
-
- pascal void debugger() extern 0xa9ff;
-
-
- pascal void _CalcCRC (SizeCode,CodePtr,crc)
- long SizeCode;
- Ptr CodePtr;
- long *crc;
- extern;
-
- /******************************************************************
- Main
- *******************************************************************/
- main(argc,argv)
-
- int argc;
- char *argv[];
-
- {
- short refnum;
- Handle CodeHandle; /* Handle to code resource */
- short IOR; /* IO Result */
- long SizeCode; /* Size of the code */
- Ptr CodePtr; /* Pointer to the code */
- long crc; /* the crc value */
-
- if (argc == 1)
- {
- fprintf(stderr,"### ERROR : No input file specified.\n");
- fprintf(stderr,"### SYNTAX: crcPatch filename\n");
- fprintf(stderr,"### DSCRPT: Calculate and patch the crc value to code segment 1.\n");
- }
- else if (argc != 2)
- {
- fprintf(stderr,"### ERROR : Wrong number of parameters specified.\n");
- fprintf(stderr,"### SYNTAX: crcPatch filename\n");
- fprintf(stderr,"### DSCRPT: Calculate and patch the crc value to code segment 1.\n");
- }
- else
- {
- refnum = openresfile(argv[1]);
- if (refnum < 0 )
- fprintf(stderr,"### ERROR : Resource file: %s can't be opened. err = %d.\n",argv[1],refnum);
- else
- {
- CodeHandle = GetResource('CODE',1);
- HLock(CodeHandle);
- IOR = ResError();
- if (IOR != 0)
- fprintf(stderr,"### ERROR : Code resource not available. Err = %d\n",IOR);
- else
- {
- /* SizeCode = SizeResource(CodeHandle);*/
- SizeCode = GetHandleSize(CodeHandle);
- SizeCode = SizeCode - 4; /* Skip first 4 bytes (Resource header) */
- CodePtr = ((Ptr)*CodeHandle) + 4; /* Skip first 4 bytes (Resource header) */
-
- _CalcCRC(SizeCode,CodePtr,&crc); /* Calc and patch the crc value */
-
- ChangedResource(CodeHandle);
- IOR = ResError();
- if (IOR != 0)
- fprintf(stderr,"### ERROR : ChangedResource. Err = %d\n",IOR);
-
- WriteResource(CodeHandle);
- IOR = ResError();
- if (IOR != 0)
- fprintf(stderr,"### ERROR : WriteResource. Err = %d\n",IOR);
-
- CloseResFile(refnum);
- IOR = ResError();
- if (IOR != 0)
- fprintf(stderr,"### ERROR : CloseResFile. Err = %d\n",IOR);
- }
- }
- }
- }
-
-